<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        function move(array, from, to) {
            if (from < 0 || to >= array.length) {
                console.error("参数错误");
                return;
            }
            const newArray = [...array];

            let item = newArray.splice(from, 1);

            newArray.splice(to, 0, ...item);
            return newArray;
        }
        let array = [1, 2, 3, 4, 5];

        console.table(move(array, 1, 3));

    </script>
</body>

</html>